//
//  JPFFunc.h
//  JPFFramework
//
//  Created by JPFei on 2019/3/5.
//  Copyright © 2019 nmo. All rights reserved.
//

#ifndef JPFFunc_h
#define JPFFunc_h

#import <UIKit/UIKit.h>
#import <objc/runtime.h>

///交换方法实现
static void swizzInstance(Class srcClass,SEL srcSel,Class tarClass,SEL tarSel);

static void swizzInstance(Class srcClass,SEL srcSel,Class tarClass,SEL tarSel)
{
    Method srcMethod = class_getInstanceMethod(srcClass, srcSel);
    Method tarMethod = class_getInstanceMethod(tarClass, tarSel);
    
    BOOL didAddMethod =
    class_addMethod(srcClass, srcSel, method_getImplementation(srcMethod), method_getTypeEncoding(srcMethod));
    
    if (didAddMethod)
    {
        class_replaceMethod(srcClass, srcSel, method_getImplementation(srcMethod),method_getTypeEncoding(srcMethod));
    }else{
        method_exchangeImplementations(srcMethod, tarMethod);
    }
}


#endif /* JPFFunc_h */
